<link rel="stylesheet" href="../css/body.css" type="text/css" />
<script type="text/javascript" src="../js/view.js"></script>

<script type="text/javascript">
arr= new Array();
function startUpload(id, conditional)
{
		$('#'+id).uploadifyUpload();
}
</script>

<script type="text/javascript">
	Ext.onReady(function(){
		$('#fileUploadname2').uploadify({
		  	'uploader'	: '../js/uploadify/uploadify.swf',
		  	'script'    : '../js/uploadify/uploadify2.php',
		  	'multi'			: true,
		  	'height'		:	'30', //height of your browse button file
		  	'width'			:	'150', //width of your browse button file
		  	'simUploadLimit' : '3', //remove this to set no limit on simultaneous uploads
		    'buttonText' : 'Browser...',
		    'displayData': 'speed',
		  	'cancelImg' : '../js/uploadify/cancel.png',
			'folder'    : '../upload/logo', //folder to save uploads to
			'scriptData': {'name':'onpress'},
			'fileExt'     : '*.jpg;*.gif;*.png;*.jpeg',
			'fileDesc'    : 'Image Files',
	  		'onAllComplete'  : function() {
				view.add_image('image_onpress');
	    	},
			'onError': function(){
				alert("Quá trình upload bị lỗi");
				window.location.reload();
			}
		});
		view.add_image('image_onpress');
		$("#btndel").click(function(){
			var ids= common.getChecked('image_onpress[]');
			if(ids == ""){
				alert("Chưa chọn hình cần xóa");
			}else{
				if(confirm("Bạn chắc chắn muốn xóa?")){
					Ext.Ajax.request({
						url:  'services/delete_image.php',
						method: 'POST',
						params: {act :'image_onpress',
							     ids : ids
							     },
						success: function ( result, request ) {	
							if (result.responseText == 1){
								alert("Xóa thành công");
									view.add_image('image_onpress');
							}
						},
						failure: function ( result, request ) {
		    			}
					});
				}
			}
		});
		$('#btnedit').click(function(){
		var ids= common.getChecked('image_onpress[]');
		if(ids ==""){
			alert("Chưa chọn nội dung cần thay đổi");
		}else{
			var list = document.getElementsByName('image_onpress[]');
			$(list).attr('disabled',true);
			view.edit_click(ids);
		}
	});
	$('#btnupdate').click(function(){
		var ids= common.getChecked('image_onpress[]');
		view.update_click('image_onpress',ids);
	});
	$('#btnallies').click(function(){
		var ids= common.getChecked('image_onpress[]');
		var index = $('#allies_onpress').val();
		if(ids ==""){
			alert("Chưa chọn nội dung cần thay đổi");
		}else{
			view.allies_click(index,ids);
		}
	});
	$('#btncancel').click(function(){
		$("#btnupdate,#btnedit,#btncancel").toggle();
		$("#btndel,#btncheck,#btnuncheck").removeAttr('disabled');
		var list = document.getElementsByName('image_onpress[]');
		$(list).removeAttr('disabled');
		var ids = common.getChecked('image_onpress[]');
		list_id = ids.split(",");
		for(var i=0 ; i< list_id.length;i++){
			$('#tb_' + list_id[i]).attr('disabled',true);
			$('#tb_' + list_id[i]).css('border','');
		}
		common.setUnCheckAll('image_onpress[]');
		if($('#btnuncheck').css('display') != 'none'){
			$('#btncheck,#btnuncheck').toggle();
		}
	});
	$('#btncheck').click(function(){
		common.setCheckAll('image_onpress[]');
		$('#btncheck,#btnuncheck').toggle();
	});
	$('#btnuncheck').click(function(){
		common.setUnCheckAll('image_onpress[]');
		$('#btncheck,#btnuncheck').toggle();
	});
	$('#btn_create_link').click(function(){
		var popupwin = common.create_window('win_create_link', 'Add Link', 'page/create_link.php', '500', '200');
		popupwin.show();
	});
	});
</script>

<h2>ONPRESS PAGE</h2>
	

<div id="uploadform">
	<hr width=100% size="1" color="" align="center">
		<h2>Upload Images</h2>
		<p>Hiển thị chức năng thêm hình ảnh vào album. Có thể chọn nhiều file</p>
		<div id="fileUploadname2">You have a problem with your javascript</div>
		<a href="javascript:startUpload('fileUploadname2')">Start Upload</a> |  <a href="javascript:$('#fileUploadname2').uploadifyClearQueue()">Clear Queue</a>
    	<p></p>
	<hr width=100% size="1" color="" align="center">

</div>
<div id="img_cm">
	<fieldset>
		<legend>Form OnPress</legend>	
	<div id="btn_del" >
		<input id="btndel" type="button" value="DELETE" />
		<input id="btncheck" type="button" value="CHECK" />
		<input id="btnuncheck" type="button" value="UNCHECK" style="display:none"/>
		<input id="btnedit" type="button" value="EDIT" />
		<input id="btnupdate" type="button" value="UPDATE" style="display:none" />
		<input id="btncancel" type="button" value="CANCEL" style="display:none" />
		<input id="btn_create_link" type="button" value="Create Link" />
		<input id="btnallies" type="button" value="ALLIES" />
	</div>	
	<div id="image">
	</div>
	</fieldset>

</div>
